//模拟在线玩家数量
var onlinePlayerNum = function() {
	// this.morningPlayerNum = 3380
	// this.nightPlayerNum = 638
	// this.playerNum = Math.floor((this.morningPlayerNum - this.nightPlayerNum) / 2)
	this.playerCount = 0
}
onlinePlayerNum.prototype.init = function() {
	var self = this
	this.redisDao.db.get("game:playerCount",function(err,value) {
		if(err || !value){
			value = 3300
		}
		self.playerCount = Number(value)
		setInterval(self.update.bind(self),10000)
	})
}
//更新
onlinePlayerNum.prototype.update = function() {
	// var base = Math.floor(Math.random() * 30) - 15
	// var add = 0
	// var hours =  (new Date()).getHours()
	// var morningFlag = true
	// if(hours < 7 || hours >= 22){
	// 	morningFlag = false
	// }
	// if(morningFlag){
	// 	//白天趋向白天值
	// 	if(this.playerNum < this.morningPlayerNum){
	// 		add += Math.floor(Math.random() * 25)
	// 	}else if(this.playerNum > this.morningPlayerNum * 1.5){
	// 		add -= Math.floor(Math.random() * 25)
	// 	}
	// }else{
	// 	//晚上趋向晚上值
	// 	if(this.playerNum > this.nightPlayerNum){
	// 		add -= Math.floor(Math.random() * 25)
	// 	}else if(this.playerNum < this.nightPlayerNum * 0.5){
	// 		add += Math.floor(Math.random() * 25)
	// 	}
	// }
	// this.playerNum += base + add
	var tmpNum = Math.floor(Math.random() * 10) + 1
	this.playerCount += tmpNum
	this.redisDao.db.set("game:playerCount",this.playerCount)
}
onlinePlayerNum.prototype.getOnlineNum = function() {
	return this.playerCount
}
module.exports = {
	id : "onlinePlayerNum",
	func : onlinePlayerNum,
	init : "init",
	lazy : true,
  	props : [{
  		name : "redisDao",
  		ref : "redisDao"
  	}]
}